package com.pandora.loan.home.mongo.dao.impl;

import com.pandora.loan.home.mongo.dao.MongoActivityDao;
import com.pandora.loan.home.mongo.entity.MongoActivity;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author developer
 */
@Repository("mongoActivityDaoImpl")
public class MongoActivityDaoImpl implements MongoActivityDao {
    @Resource
    private MongoTemplate mongoTemplateNetLoan;

    @Override
    public List<MongoActivity> selectByLength(int length) {
        Query query = new Query();
        query.with(new Sort(Sort.Direction.DESC, "_id"));
        query.limit(length);
        List<MongoActivity> li = mongoTemplateNetLoan.find(query, MongoActivity.class);
        return li;
    }
}
